package com.cennavi.bigdata.baotou.test;

import com.alibaba.fastjson.JSONObject;
import com.cennavi.bigdata.baotou.util.DateUtils;
import com.mongodb.*;

import java.util.Date;

/**
 * Created by zuoweiguang on 2017/3/10.
 * 包头市交通状况监测系统 - 交通管制模块
 * 程序类型：测试脚本
 * 功能：插入测试数据
 */
public class MakeTrafficControlTestData {

    private MongoClient mongoClient = null;
    private DB db = null;
    private DBCollection trafficControlCol = null;

    public MakeTrafficControlTestData() {
        //获取 mongo 的连接
//        ServerAddress serverAddress = new ServerAddress("15.32.12.63", 27017);
        ServerAddress serverAddress = new ServerAddress("123.207.109.239", 27017);
        mongoClient = new MongoClient(serverAddress);
        db = mongoClient.getDB("baotou_traffic");
        trafficControlCol = db.getCollection("traffic_control");
    }

    public void makeTestData() {

       /* String data1 = "{\"title\": \"管制管制管制\",\"road_descrip\": \"路段描述路段描述路段描述\", \"descrip_info\": \"描述信息描述信息描述信息\",\n" +
                "            \"detour_suggest\": \"绕行建议绕行建议绕行建议\", \"start_time\": \"生效时间生效时间\", \"end_time\": \"失效时间失效时间\",\n" +
                "            \"control_type\": \"point\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [109.85233380803521, 40.65632504724073]}}";

        String data2 = "{\"title\": \"管制管制管制\", \"road_descrip\": \"路段描述路段描述路段描述\", \"descrip_info\": \"描述信息描述信息描述信息\",\n" +
                "            \"detour_suggest\": \"绕行建议绕行建议绕行建议\", \"start_time\": \"生效时间生效时间\", \"end_time\": \"失效时间失效时间\",\n" +
                "            \"control_type\": \"linestring\",\n" +
                "             \"geometry\": {\"type\": \"LineString\",\n" +
                "                          \"coordinates\": [[109.84908557983044,40.65380247526522], [109.84907936685488,40.65268266993999],\n" +
                "                                          [109.84894459577015,40.651061660415934], [109.84851803501181,40.64575455286655]]}}";

        String data3 = "{\"title\": \"管制管制管制\", \"road_descrip\": \"路段描述路段描述路段描述\", \"descrip_info\": \"描述信息描述信息描述信息\",\n" +
                "            \"detour_suggest\": \"绕行建议绕行建议绕行建议\", \"start_time\": \"生效时间生效时间\", \"end_time\": \"失效时间失效时间\",\n" +
                "            \"control_type\": \"polygon\",\n" +
                "             \"geometry\": {\"type\": \"Polygon\",\n" +
                "                          \"coordinates\": [[[109.85046585686251,40.64688232321035], [109.85395456656994,40.646580287532885],\n" +
                "                                           [109.85373826411757,40.64426281012399], [109.85023790622608,40.64399699035425],\n" +
                "                                           [109.85046585686251,40.64688232321035]]]}}";*/

        String data1 = "{\"title\": \"临时管制\",\"road_descrip\": \"少先路（阿尔丁大街至民族东路）\", \"descrip_info\": \"以下道路禁止摩托车(包含二轮摩托车、三轮摩托车)通行\"," +
                "            \"detour_suggest\": \"无\", \"start_time\": \"2017-03-29 07:00\", \"end_time\": \"2017-03-29 22:00\"," +
                "            \"control_type\": \"temporary\", \"geometry\": {\"type\": \"LineString\", \"coordinates\": [[109.83977935176688,40.65250951264895],[109.84160568200622,40.65242589939129]" +
                ",[109.84192843865043,40.652431871762644],[109.84299117393232,40.652360203181644],[109.84387285058256,40.652336313631594]]},"+
                " \"detour_temporary\":\"\"}";

        String data2 = "{\"title\": \"临时管制\",\"road_descrip\": \"乌兰道（市府东路至白云路段）\", \"descrip_info\": \"以下道路禁止摩托车(包含二轮摩托车、三轮摩托车)通行\"," +
                "            \"detour_suggest\": \"无\", \"start_time\": \"2017-03-29 07:00\", \"end_time\": \"2017-03-29 22:00\"," +
                "            \"control_type\": \"temporary\", \"geometry\": {\"type\": \"LineString\", \"coordinates\": [[109.8444475148936,40.65894344388843],[109.84209375307745,40.659068851489536]" +
                ",[109.84185758945972,40.65906885129354],[109.84036188795739,40.65912259733747],[109.8385827902888,40.65921217378906],[109.83640221495119,40.65931369383773]" +
                ",[109.83493012971786,40.6594211854397],[109.83390675500448,40.65946895944873],[109.83122236443847,40.65960033780178],[109.82789645625911,40.659750611085826]" +
                ",[109.82647947583166,40.65982824332761],[109.82362189876244,40.65996559268015],[109.82277958256208,40.659995451170914],[109.82184280111267,40.66011488510114]" +
                ",[109.82158302137009,40.66012085679438],[109.81981179591781,40.66021043209133],[109.81776486824646,40.660300007156366],[109.81682808679705,40.66032986552494]" +
                ",[109.81585007594191,40.660364784759565],[109.81525179534594,40.66041852975002],[109.81431501389642,40.66044241641103],[109.81292952199385,40.66051407631471]" +
                ",[109.81182742614482,40.66060365108365]]}," +
                " \"detour_temporary\":\"\"}";

        String data3 = "{\"title\": \"临时管制\",\"road_descrip\": \"林荫路（乌兰道至少先路段）\", \"descrip_info\": \"以下道路禁止摩托车(包含二轮摩托车、三轮摩托车)通行\"," +
                "            \"detour_suggest\": \"无\", \"start_time\": \"2017-03-29 07:00\", \"end_time\": \"2017-03-29 22:00\"," +
                "            \"control_type\": \"temporary\", \"geometry\": {\"type\": \"LineString\", \"coordinates\": [[109.82157489690422,40.660136988026494],[109.82147772858667,40.65789798775012]" +
                ",[109.82145343628974,40.657722918803785],[109.82127124567768,40.65561236187358],[109.82112153649848,40.653524698347155]]}," +
                " \"detour_temporary\":\"\"}";

        String data4 = "{\"title\": \"临时管制\",\"road_descrip\": \"钢铁大街（一宫环岛至白云路）\", \"descrip_info\": \"以下道路禁止载货汽车及摩托车等其他机动车辆通行，只允许客车通行（长途大型客车除外）\"," +
                "            \"detour_suggest\": \"无\", \"start_time\": \"2017-03-29 06:00\", \"end_time\": \"2017-03-29 22:00\"," +
                "            \"control_type\": \"temporary\", \"geometry\": {\"type\": \"LineString\", \"coordinates\": [[109.87793010940226,40.65509764244365],[109.86928049616614,40.655524822886434]" +
                ",[109.86149115181729,40.65590453653979],[109.85704903577863,40.656106258534805],[109.84933408332626,40.65646889361827],[109.8443132408753,40.6566706140066]" +
                ",[109.83849478133232,40.65697839181408],[109.83090877334007,40.65734623142234],[109.82157094424673,40.65785645741491],[109.8117013131914,40.65836667946786]]}," +
                " \"detour_temporary\":\"\"}";

        String data5 = "{\"title\": \"临时管制\",\"road_descrip\": \"赛音道（文化路至科学路）\", \"descrip_info\": \"禁止机动车由南向北行驶，只允许机动车由北向南行驶\"," +
                "            \"detour_suggest\": \"赛音道（科学路至文化路）\", \"start_time\": \"2017-03-29 07:00\", \"end_time\": \"2017-03-29 22:00\"," +
                "            \"control_type\": \"temporary\", \"geometry\": {\"type\": \"LineString\", \"coordinates\": [[109.87457668343512,40.67111398091993],[109.87302538686305,40.669435820821576]" +
                ",[109.87211437947866,40.66845818647772],[109.87085472085744,40.667061899032035],[109.8705754435116,40.66675160564276],[109.86964846368835,40.6656953694513]]}," +
                " \"detour_temporary\":{\"type\": \"LineString\", \"coordinates\": [[109.86961288717129,40.66571532483309],[109.87053924711665,40.66676931644176],[109.87082469515809,40.66708796177062]" +
                ",[109.87208532823678,40.668476202558594],[109.87298475894403,40.66946070476928],[109.87379270934929,40.670306421818225],[109.87453915624519,40.67115606010398]]}}";

        String data1_1 = "{\"title\": \"非临时管制\",\"road_descrip\": \"少先路（阿尔丁大街至民族东路）\", \"descrip_info\": \"每天07时至22时，以下道路禁止摩托车(包含二轮摩托车、三轮摩托车)通行\"," +
                "            \"detour_suggest\": \"无\", \"start_time\": \"2016-11-19\", \"end_time\": \"2016-11-19\", \"control_time\": \"07:00-22:00\"," +
                "            \"control_type\": \"not_temporary\", \"geometry\": {\"type\": \"LineString\", \"coordinates\": [[109.83977935176688,40.65250951264895],[109.84160568200622,40.65242589939129]" +
                ",[109.84192843865043,40.652431871762644],[109.84299117393232,40.652360203181644],[109.84387285058256,40.652336313631594]]}," +
                " \"detour_temporary\":\"\"}";

        String data1_2 = "{\"title\": \"非临时管制\",\"road_descrip\": \"乌兰道（市府东路至白云路段）\", \"descrip_info\": \"每天07时至22时，以下道路禁止摩托车(包含二轮摩托车、三轮摩托车)通行\"," +
                "            \"detour_suggest\": \"无\", \"start_time\": \"2016-11-19\", \"end_time\": \"2016-11-19\", \"control_time\": \"07:00-22:00\"," +
                "            \"control_type\": \"not_temporary\", \"geometry\": {\"type\": \"LineString\", \"coordinates\": [[109.8444475148936,40.65894344388843],[109.84209375307745,40.659068851489536]" +
                ",[109.84185758945972,40.65906885129354],[109.84036188795739,40.65912259733747],[109.8385827902888,40.65921217378906],[109.83640221495119,40.65931369383773]" +
                ",[109.83493012971786,40.6594211854397],[109.83390675500448,40.65946895944873],[109.83122236443847,40.65960033780178],[109.82789645625911,40.659750611085826]" +
                ",[109.82647947583166,40.65982824332761],[109.82362189876244,40.65996559268015],[109.82277958256208,40.659995451170914],[109.82184280111267,40.66011488510114]" +
                ",[109.82158302137009,40.66012085679438],[109.81981179591781,40.66021043209133],[109.81776486824646,40.660300007156366],[109.81682808679705,40.66032986552494]" +
                ",[109.81585007594191,40.660364784759565],[109.81525179534594,40.66041852975002],[109.81431501389642,40.66044241641103],[109.81292952199385,40.66051407631471]" +
                ",[109.81182742614482,40.66060365108365]]}," +
                " \"detour_temporary\":\"\"}";

        String data1_3 = "{\"title\": \"非临时管制\",\"road_descrip\": \"林荫路（乌兰道至少先路段）\", \"descrip_info\": \"每天07时至22时，以下道路禁止摩托车(包含二轮摩托车、三轮摩托车)通行\"," +
                "            \"detour_suggest\": \"无\", \"start_time\": \"2016-11-19\", \"end_time\": \"2016-11-19\", \"control_time\": \"07:00-22:00\"," +
                "            \"control_type\": \"not_temporary\", \"geometry\": {\"type\": \"LineString\", \"coordinates\": [[109.82157489690422,40.660136988026494],[109.82147772858667,40.65789798775012]" +
                ",[109.82145343628974,40.657722918803785],[109.82127124567768,40.65561236187358],[109.82112153649848,40.653524698347155]]}," +
                " \"detour_temporary\":\"\"}";

        String data1_4 = "{\"title\": \"非临时管制\",\"road_descrip\": \"钢铁大街（一宫环岛至白云路）\", \"descrip_info\": \"每天06时至22时、以下道路禁止载货汽车及摩托车等其他机动车辆通行，只允许客车通行（长途大型客车除外）\"," +
                "            \"detour_suggest\": \"无\", \"start_time\": \"2016-11-19\", \"end_time\": \"2016-11-19\", \"control_time\": \"06:00-22:00\"," +
                "            \"control_type\": \"not_temporary\", \"geometry\": {\"type\": \"LineString\", \"coordinates\": [[109.87793010940226,40.65509764244365],[109.86928049616614,40.655524822886434]" +
                ",[109.86149115181729,40.65590453653979],[109.85704903577863,40.656106258534805],[109.84933408332626,40.65646889361827],[109.8443132408753,40.6566706140066]" +
                ",[109.83849478133232,40.65697839181408],[109.83090877334007,40.65734623142234],[109.82157094424673,40.65785645741491],[109.8117013131914,40.65836667946786]]}," +
                " \"detour_temporary\":\"\"}";

        String data1_5 = "{\"title\": \"非临时管制\",\"road_descrip\": \"赛音道（文化路至科学路）\", \"descrip_info\": \"每天07时至22时，禁止机动车由南向北行驶，只允许机动车由北向南行驶\"," +
                "            \"detour_suggest\": \"赛音道（科学路至文化路）\", \"start_time\": \"2016-11-19\", \"end_time\": \"2016-11-19\", \"control_time\": \"07:00-22:00\"," +
                "            \"control_type\": \"not_temporary\", \"geometry\": {\"type\": \"LineString\", \"coordinates\": [[109.87457668343512,40.67111398091993],[109.87302538686305,40.669435820821576]" +
                ",[109.87211437947866,40.66845818647772],[109.87085472085744,40.667061899032035],[109.8705754435116,40.66675160564276],[109.86964846368835,40.6656953694513]]}," +
                " \"detour_temporary\":{\"type\": \"LineString\", \"coordinates\": [[109.86961288717129,40.66571532483309],[109.87053924711665,40.66676931644176],[109.87082469515809,40.66708796177062]" +
                ",[109.87208532823678,40.668476202558594],[109.87298475894403,40.66946070476928],[109.87379270934929,40.670306421818225],[109.87453915624519,40.67115606010398]]}}";

        try {
            //删除已存在的表
            System.out.println("drop collection:traffic_control");
            trafficControlCol.drop();
            //插入测试数据
            System.out.println("insert test data......");
           /* trafficControlCol.insert(BasicDBObject.parse(data1));
            trafficControlCol.insert(BasicDBObject.parse(data2));
            trafficControlCol.insert(BasicDBObject.parse(data3));*/
            BasicDBObject parse1 = BasicDBObject.parse(data1);
            parse1.put("update_time", DateUtils.DateFormatUnit.DATE_TIME.getDateStr(new Date()));
            trafficControlCol.insert(parse1);
            BasicDBObject parse2 = BasicDBObject.parse(data2);
            parse2.put("update_time", DateUtils.DateFormatUnit.DATE_TIME.getDateStr(new Date()));
            trafficControlCol.insert(parse2);
            BasicDBObject parse3 = BasicDBObject.parse(data3);
            parse3.put("update_time", DateUtils.DateFormatUnit.DATE_TIME.getDateStr(new Date()));
            trafficControlCol.insert(parse3);
            BasicDBObject parse4 = BasicDBObject.parse(data4);
            parse4.put("update_time", DateUtils.DateFormatUnit.DATE_TIME.getDateStr(new Date()));
            trafficControlCol.insert(parse4);
            BasicDBObject parse5 = BasicDBObject.parse(data5);
            parse5.put("update_time", DateUtils.DateFormatUnit.DATE_TIME.getDateStr(new Date()));
            trafficControlCol.insert(parse5);
            BasicDBObject parse1_1 = BasicDBObject.parse(data1_1);
            parse1_1.put("update_time", DateUtils.DateFormatUnit.DATE_TIME.getDateStr(new Date()));
            trafficControlCol.insert(parse1_1);
            BasicDBObject parse1_2 = BasicDBObject.parse(data1_2);
            parse1_2.put("update_time", DateUtils.DateFormatUnit.DATE_TIME.getDateStr(new Date()));
            trafficControlCol.insert(parse1_2);
            BasicDBObject parse1_3 = BasicDBObject.parse(data1_3);
            parse1_3.put("update_time", DateUtils.DateFormatUnit.DATE_TIME.getDateStr(new Date()));
            trafficControlCol.insert(parse1_3);
            BasicDBObject parse1_4 = BasicDBObject.parse(data1_4);
            parse1_4.put("update_time", DateUtils.DateFormatUnit.DATE_TIME.getDateStr(new Date()));
            trafficControlCol.insert(parse1_4);
            BasicDBObject parse1_5 = BasicDBObject.parse(data1_5);
            parse1_5.put("update_time", DateUtils.DateFormatUnit.DATE_TIME.getDateStr(new Date()));
            trafficControlCol.insert(parse1_5);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            mongoClient.close();
            System.out.println("process done!!");
        }
    }

    public static void main(String[] args) {
        MakeTrafficControlTestData mctd = new MakeTrafficControlTestData();
        mctd.makeTestData();
    }

}
